package com.sky.sky_server.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import com.sky.sky_pojo.dto.DishItemVO;
import com.sky.sky_pojo.dto.SetmealOverViewVO;
import com.sky.sky_pojo.entity.Setmeal;
import com.sky.sky_pojo.entity.SetmealQueryPage;
import com.sky.sky_server.annotation.AutoFill;
import com.sky.sky_common.enumeration.OperationType;

@Mapper
public interface SetmealMapper {
    /**
     * 根据分类id查询套餐数量
     * @param categoryId
     * @return
     */
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    int countByCategoryId(Long categoryId);

    /**
     * 根据分类id查询套餐列表
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> selectByCategoryId(Long categoryId);

    /**
     * 根据套餐id查询包含的菜品
     * @param setmealId
     * @return
     */
    @Select("select d.name, d.description, d.image, s.copies from setmeal_dish s left join dish d on s.dish_id = d.id where s.setmeal_id = #{setmealId}")
    List<DishItemVO> selectDishBySetmealId(Long setmealId);

    /**
     * 新增套餐
     * @param setmeal
     * @return
     */
    @AutoFill(OperationType.INSERT)
    @Insert("insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealQueryPage
     * @return
     */
    List<Setmeal> selectByCondition(SetmealQueryPage setmealQueryPage);

    /**
     * 修改套餐
     * @param setmeal
     * @return
     */
    @AutoFill(OperationType.UPDATE)
    int update(Setmeal setmeal);


    /**
     * 根据套餐id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal selectById(Long id);

    /**
     * 批量查询
     * @param ids
     * @return
     */
    List<Setmeal> selectBatchIds(List<Long> ids);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    int delteByIds(List<Long> ids);


    /**
     * 查询套餐总览
     * @return
     */
    SetmealOverViewVO overviewSetmeals();
}
